<template>
  <el-form ref="form" :model="form" label-width="160px">
    <el-form-item label="沟通内容限制">
      <label>字符检测：</label>
      <el-radio-group v-model="form['char_check']" size="small">
        <el-radio :label="1">开启</el-radio>
        <el-radio :label="2">关闭</el-radio>
      </el-radio-group>
      <el-input v-if="form['char_check']" v-model="form['char_length']" min="0" size="small" type="number" style="width: 240px;margin: 5px 0 0 15px;">
        <template slot="prepend">至少输入</template>
        <template slot="append">字符</template>
      </el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('form')">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  export default {
    components: {},
    data() {
      return {
        form: {}
      }
    },
    mounted() {
      this.loadData();
    },
    methods: {
      loadData() {
        const url = 'customer/getSetting'
        this.$store.dispatch('GetConnect', { url }).then(res => {
          this.form = res.data
        }).catch(e => {
          this.$message.error(e.msg + ',请刷新或联系管理员')
        })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const data = this.form
            const url = 'customer/saveSetting'
            this.$store.dispatch('GetConnect', { url, data }).then(res => {
              this.$message.success(res.msg)
              this.loadData()
            }).catch((err) => {
              this.$message.error(err.msg)
            })
          } else {
            this.$message.error('提交失败,请检查必填项')
          }
        })
      }
    }
  }
</script>

<style lang="scss" type="text/scss" scoped>

</style>

